/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mundialfp.view.tables.paisPuntos;

import java.awt.Color;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author pferraz
 */
public class TableCustom2CellRender extends DefaultTableCellRenderer {

    private final int cupos;
    private final Color backgroundColor = getBackground();

    public TableCustom2CellRender(int cupos) {
        this.cupos = cupos;
    }

    private static final long serialVersionUID = 6703872492730589499L;

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Component cellComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        if (row < cupos) {
            if (row % 2 == 0) {
                cellComponent.setBackground(new Color(168, 221, 16));
            } else {
                cellComponent.setBackground(new Color(147, 202, 16));
            }
        } else {
            cellComponent.setBackground(backgroundColor);
        }
        JLabel label = (JLabel) cellComponent;
        if (value instanceof Icon) {
            label.setText(null);
            label.setIcon((Icon) value);
        } else {
            label.setText(value.toString());
            label.setIcon(null);
        }

        return cellComponent;
    }

}
